# -*- coding: utf-8 -*-
from datetime import datetime
import pandas as pd
import numpy as np

if __name__ == '__main__':
    """
        重采样
    """
    date_range = pd.date_range("2018-01-01", periods=100, freq="D")
    s_obj = pd.Series(np.random.randint(1,10,100), date_range)
    # print s_obj
    resample_obj = s_obj.resample("M").sum()
    print resample_obj
    print s_obj.resample("M").mean()
    print "--------ohlc  开始值，最高值，最低值，结束值-----------------"
    print s_obj.resample("M").ohlc()
    print '--------升采样--------------------------'
    frame = pd.DataFrame(np.random.randn(5, 3), index=pd.date_range('2018-1-1', periods=5, freq="W-MON"),
                         columns=['a', 'b', 'c'])
    print frame
    print "升采样----按天"
    print frame.resample("D").asfreq()
    print "-----补数据-----拿前面的数据补后面的数据----"
    print frame.resample("D").ffill(2)
    print "-------------拿后面的数据补充前面的数据-----------------------------"
    print frame.resample("D").bfill(2)
    print "------------------------------------------------------"
    print frame.resample("D").fillna("ffill")
    print "---------------按照线性补全数据-------------------------------"
    print frame.resample("D").interpolate("linear")